package com.syx.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.syx.entity.User;
import com.syx.service.BmbService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class BmbController {
    @Resource
    private BmbService bmbService;

    @RequestMapping("login.do")
    public String login(User user, HttpSession session){
        List list = bmbService.login(user);
        if (list.size()>0){
            session.setAttribute("user",list);
            return "redirect:list.do";
        }else {
            return "redirect:index.jsp";
        }

    }

    @RequestMapping("list.do")
    public String bmbList(Model model,
                          String pic,
                          String name,
                          String names,
                          String bbidMin,
                          String bbidMax,
                          String cbbidMin,
                          String cbbidMax,
                          String timeMin,
                          String timeMax,
                          @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                          HttpSession session){
        PageHelper.startPage(pageNum,3);
        Map map = new HashMap();
        map.put("pic",pic);
        map.put("name",name);
        map.put("names",names);
        map.put("bbidMin",bbidMin);
        map.put("bbidMax",bbidMax);
        map.put("cbbidMin",cbbidMin);
        map.put("cbbidMax",cbbidMax);
        map.put("timeMin",timeMin);
        map.put("timeMax",timeMax);
        List list = bmbService.bmbList(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("map",map);
        return "list";
    }

    @RequestMapping("addTo.do")
    public String addTo(){
        return "add";
    }

    @RequestMapping("add.do")
    @ResponseBody
    public Object add(){
        return 1;
    }
}
